package com.cyh.nio;

import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;

/**
 * 内存映射文件I/O
 * */
public class BufferDemo06 {

    static private final int start = 0;
    static private final int size = 1024;
    public static void main(String[] args) throws Exception {
        RandomAccessFile raf = new RandomAccessFile("D:\\cyh\\work_java\\TestNioOrIo\\src\\com\\cyh\\6.txt", "rw");
        FileChannel fc = raf.getChannel();
        MappedByteBuffer mbb = fc.map(FileChannel.MapMode.READ_WRITE, start, size);

        mbb.put(0, (byte)97);
        mbb.put(1023, (byte)122);
        raf.close();
    }
}
